package com.yndsoft.jc.ui.xiaoyao;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.yndsoft.jc.R;

/**
 * Created by Administrator on 2016-08-12.
 * @Description:自定义对话框
 */
public class XYProgressDialog extends ProgressDialog {
    private AnimationDrawable mAnimation;
    private Context context;
    private ImageView loadingImg;
    private TextView loadingText;
    private String loadingTip;
    private int count = 0;
    private String oldLoadingTip;

    public XYProgressDialog(Context context, String loadingTip) {
        super(context);
        this.context = context;
        this.loadingTip = loadingTip;
        setCanceledOnTouchOutside(true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initData();
    }

    private void initData() {
        //loadingImg.setBackgroundResource(mResid);
        // 通过ImageView对象拿到背景显示的AnimationDrawable
        mAnimation = (AnimationDrawable) loadingImg.getBackground();
        // 为了防止在onCreate方法中只显示第一帧的解决方案之一
        loadingImg.post(new Runnable() {
            @Override
            public void run() {
                mAnimation.start();
            }
        });
        loadingText.setText(loadingTip);
    }

    public void setContent(String str) {
        loadingText.setText(str);
    }

    private void initView() {
        setContentView(R.layout.layout_loading);
        loadingText = (TextView) findViewById(R.id.loading_tip_txt);
    }
}